package com.liuzhongni.wahahanews.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.google.gson.Gson;
import com.liuzhongni.wahahanews.R;
import com.liuzhongni.wahahanews.adapter.ListViewAdapterOfVideo;
import com.liuzhongni.wahahanews.singleton.VolleySingleton;
import com.liuzhongni.wahahanews.videoclass.VideoFirst;

/**
 * Created by dllo on 16/1/7.
 */
public class VideoFragment extends Fragment {
    private ListView listView;
    private ListViewAdapterOfVideo adapterOfVideo;
    private VideoFirst videoFirst =new VideoFirst();
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_video, null);
        listView = (ListView) view.findViewById(R.id.video_lv);

        final String url = "http://c.3g.163.com/nc/video/home/0-10.html";
        StringRequest request = new StringRequest(url, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                Log.d("VideoFragment", response);
                Gson gson = new Gson();
                videoFirst = gson.fromJson(response, VideoFirst.class);
                adapterOfVideo = new ListViewAdapterOfVideo(videoFirst,getActivity());
                listView.setAdapter(adapterOfVideo);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Log.d("VideoFragment", "解析失败");
            }
        });
        VolleySingleton.getOurInstance().addRequest(request);

//        getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
//        videoView = (VideoView) view.findViewById(R.id.vv);
//        videoView.setVideoURI(Uri.parse("http://flv2.bn.netease.com/videolib3/1601/14/JyYfI8980/SD/JyYfI8980-mobile.mp4"));
//        MediaController mediaController = new MediaController(getActivity());
//        videoView.setMediaController(mediaController);
//        videoView.start();




        return view;
    }
    @Override
    public void onPause() {
        super.onPause();
        Log.d("VideoFragment", "pause");
    }

    @Override
    public void onStop() {
        super.onStop();
        Log.d("VideoFragment", "stop");
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        Log.d("VideoFragment", "destroyview");
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.d("VideoFragment", "destroy");
    }

    @Override
    public void onDetach() {
        super.onDetach();
        Log.d("VideoFragment", "detach");
    }
}
